﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace CowsAndBulls
{
    class Player
    {
        private int[] guessedNumber = new int[4];
        private string command = "";
        private bool enteredCommand = false;

        public Player()
        {
        }

        public bool EnteredCommand
        {
            get
            {
                return enteredCommand;
            }
            set
            {
                enteredCommand = value;
            }
        }

        public int[] GuessedNumber
        {
            get
            {
                return guessedNumber;
            }
            set
            {
                guessedNumber = value;
            }
        }

        public string Command
        {
            get
            {
                return command;
            }
            set
            {
                command = value;
            }
        }

        //returns false if the entered number is unvalid, otherwise determines whether entered is a command or a valid number
        public bool GuessNumber(string command)
        {
            this.command = command;
            try
            {
                int.Parse(command);
            }
            catch (FormatException e)
            {
                enteredCommand = true;
                return true;
            }
            catch (OverflowException ex)
            {
                //to big entered number
            }
            if (command.Length != 4)
            {
                Console.WriteLine("Please, enter a four digit number XXXX!");
                return false;
            }
            else
            {
                char[] nums = this.command.ToCharArray();
                for (int i = 0; i < guessedNumber.Length; i++)
                {
                    guessedNumber[i] = int.Parse(nums[i].ToString());
                }
                enteredCommand = false;
                return true;
            }
        }

        public static void ShowInitMessage()
        {
            Console.Write("Welcome to \"Bulls and Cows\" game. Please try to guess my secret 4-digit number.\n");
            Console.Write("Use 'top' to view the top scoreboard, \'restart\' to start a new game and \'help\'\n");
            Console.Write("to cheat and \'exit\' to quit the game.\n");
        }
    }
}
